import os

def count_labels(txt_folder):
    label_counts = {}

    # 获取txt文件夹中的所有文件
    txt_files = [f for f in os.listdir(txt_folder) if f.endswith('.txt')]

    # 遍历每个txt文件
    for txt_file in txt_files:
        # 读取txt文件内容
        with open(os.path.join(txt_folder, txt_file), 'r') as f:
            lines = f.readlines()

        # 遍历每一行
        for line in lines:
            # 提取类别标签
            label = line.split()[0]

            # 统计标签数量
            if label in label_counts:
                label_counts[label] += 1
            else:
                label_counts[label] = 1

    return label_counts


txt_folder = 'D:/datasets/visDrone2019/VisDrone2019-DET-val/labels'  # txt文件夹路径

# 统计标签数量
counts = count_labels(txt_folder)

# 打印结果
for label, count in counts.items():
    print(f'{label}: {count}')